home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / misc1s.zoo / misc1 / combine / README < prev    next >
Encoding:
Text File  |  1989-06-23  |  15.2 KB  |  338 lines

  1. .so /usr/lib/tmac/tmac.m
  2. .de )k                      \" remove -- lines at top of page
  3. ..
  4. .nr Cl 7                    \" keep level 1-7 headers in table of contents
  5. .nr Hb 7                    \" all text after heading starts on new line
  6. .nr Hs 7                    \" all headers followed by 1 line
  7. .nr Li 10                   \" AL indent: 10 spaces
  8. .nr Pi 10                   \" BL indent: 10 spaces
  9. .nr Ps 2                    \" paragraph spacing: 2 lines
  10. .ds HF 3 3 3 3 2 2 2        \" header fonts: bold, italic, normal
  11. .ds HP +6 +4 +2 +2          \" print first level headings 2 ps larger
  12. .ds T \t
  13. .ll 6.5i
  14. .de HX                \" macro to ensure 15 lines on page before heading
  15. .nr ;3 (15-\\n(;0)v
  16. ..
  17. .de HZ                      \" macro to output a blank line after heading
  18. .sp 0.5v
  19. ..
  20. .PH "''Combine Utility Design Spec''"
  21. .PF "'' - Page \\\\nP -''"
  22. .TL
  23. Combine Utility
  24. .br
  25. Design Specification
  26. .AF "Harris Computer Systems"
  27. .AU "Cliff Van Dyke"
  28. .MT 4
  29. .ce
  30. January 1985
  31. \}
  32. This utility compares the differences in 3 source files and produces
  33. a result file.
  34. .H 1 "Invocation Sequence"
  35. The combine utility accepts the following UNIX-like invocation sequence.
  36.  
  37.    combine [option-args] old_file new1_file [new2_file] [>list_output]
  38.  
  39. where 'old_file' is the name of the original file, 'new1_file' is a file
  40. containing modification to 'old_file', and 'new2_file' is a file containing
  41. a different set of modifications to 'old_file'. (Actually, see the
  42. functionality section for a description of other possible uses.)
  43.  
  44. where the option arguments are:
  45. .VL 10
  46. .LI -b
  47. Blank compress option --
  48. Causes COMBINE to treat all sequences of blanks and horizontal tabs
  49. as a single blank.
  50. .LI -B
  51. Blank remove option --
  52. Causes COMBINE to ignore all blanks and horizontal tabs in a line
  53. when comparing lines.
  54. .LI "-c #,#"
  55. Column specification option -- Specifies the column range to be compared.
  56. If column range is not specified, columns 1 through 135 are compared.
  57. The number of the
  58. first column to compare immediately follows the -c option.
  59. The number of the last column to compare is separated from the first column
  60. to compare by a comma.
  61. Up to 32 different column ranges may be given.
  62.  
  63. For example,
  64.  
  65.       combine -c10,20 a b c
  66.  
  67. compares only columns 10 through 20.
  68.  
  69. IMPORTANT NOTE: On VOS, the comma which separates the column values must
  70. be enclosed in quotes.
  71. .LI "-d flag"
  72. Debug options -- specifies how much debug information is to be output.
  73. The possibilities are: -d1, pass1 debug; -d2, pass2 debug; -d3, pass3 debug;
  74. -d4, pass4 debug; -d5, pass5 debug; and -da, all debug.
  75. .LI "-e area"
  76. MERGE editor option -- specifies the name of the disk area to write the
  77. MERGE script to. This script contains adequate information to allow MERGE
  78. to edit the 'old' file and insert the changes from
  79. the 'new1' and 'new2' files.
  80. The file name is specified by the argument following the -e option.
  81. This option is not yet implemented.
  82. .LI "-h area"
  83. HED editor option -- specifies the name of the disk area to write the
  84. HED script to. This script contains adequate information to allow HED
  85. to highlight changes to the 'old' file which produce the 'new1' and 'new2'
  86. files.
  87. The file name is specified by the argument following the -h option.
  88. .LI "-p #"
  89. Postfix option -- The number of unchanged lines to output to the standard
  90. output file following any group of changed lines.
  91. The number of unchanged lines is specified by the argument following the -p
  92. option. The default is 5.
  93. .LI "-P #"
  94. Prefix option -- The number of unchanged lines to output to the standard
  95. output file prior to any group of changed lines.
  96. The number of unchanged lines is specified by the argument following the -p
  97. option. The default is 5.
  98. .LI -q
  99. Quiet option -- Specifies that no output is to be generated to the standard
  100. output file if no changes are detected.
  101. .LI "-1 text"
  102. New1 file description -- Symbolic description of the 'new1' file. This text
  103. is printed as the description of the new1 file on the listing output and
  104. HED output file.
  105. .LI "-2 text"
  106. New2 file description -- Symbolic description of the 'new2' file. This text
  107. is printed as the description of the new1 file on the listing output and
  108. HED output file.
  109. .LE
  110. .H 1 Uses
  111. .H 2 "Two file comparison"
  112. The combine utility may be used to perform a simple two file comparison
  113. by merely omitting the name of the third file.
  114. .H 2 "Three file comparison"
  115. The combine utility is best suited to do a three file comparison.
  116. Consider a file which is being modified along two development paths.
  117. The original copy of the file with no modifications is called the 'old' file.
  118. The copy modified along one development path is called the 'new1' file.
  119. The copy modified along the other development path is called the 'new2' file.
  120. The following is a guide for producing a 'merged' file which contains
  121. both set of modifications.
  122.  
  123. First, combine is called with the following command line:
  124.  
  125.    combine -h temp_file old new1 new2 >listing
  126.  
  127. The output in the 'listing' file is a 'pretty' summary of the changes.
  128. The 'temp_file' contains all of the lines from the 'old', 'new1' and
  129. 'new2' files combined with control lines. A control line identifies those
  130. portions of the 'temp_file' which represent modifications made by the
  131. 'new1' and 'new2' files.
  132.  
  133. Text which is inserted by the 'new1' or 'new2' file is surrounded by an
  134. ~~Insert line and an ~End line. The ~~Insert line also contains comments
  135. indicating which of the two files the inserted lines came from and whether
  136. the insertion was involved in a 'move' operation.
  137. In the example below, the line 'apple' was inserted between two already
  138. existing lines 'bob' and 'fred'.
  139.  
  140.  
  141.     bob
  142.     ~~Insert 'file2'
  143.     apple
  144.     ~End of changes
  145.     fred
  146.  
  147.  
  148. Text which is deleted by the 'new1' or 'new2' file is surrounded by
  149. an ~~Delete line and an ~End line. The ~~Delete line also contains comments
  150. indicating which of the two files deleted the specified lines an whether
  151. the deletion is a side effect of a 'move' operation.
  152. In the example below, the line 'apple' was deleted from between the
  153. lines 'bob' and 'fred'.
  154.  
  155.  
  156.     bob
  157.     ~~Delete 'file1'
  158.     apple
  159.     ~End of changes
  160.     fred
  161.  
  162.  
  163. The 'temp_file' may be edited with any text editor. Changes in the 'temp_file'
  164. can easily be found by finding lines with two tildas (~~) on them. Changes
  165. which are correct should be left alone. Changes which are wrong should be
  166. fixed. Deleted text can be allowed to remain in the file by merely deleting
  167. to ~~Delete line. Things to watch out for during this process include:
  168. the ~~Delete line. Things to watch out for during this process include:
  169. Lines which are inserted by both the 'new1' and 'new2' files, and lines
  170. which are deleted by both the 'new1' and 'new2' files.
  171.  
  172. After all of the changes have been made in the tempfile, the 'combine2'
  173. utility should be used to produce the merged file. Combine2 is called
  174. with the following command line:
  175.  
  176.  
  177.       combine2 temp_file merged_file
  178.  
  179.  
  180. Combine2 produces a merged file by removing the control lines and the deleted
  181. lines from the temp file. If the name of the temp file is omitted, standard
  182. input is used. If the name of the merged file is omitted, standard output
  183. is used.
  184. .H 1 Algorithm
  185. Combine uses the general algorithm as described in "A technique for Isolating
  186. differences between files"; Communications of the ACM; April 1978; Volume 21
  187. Number 4. This document presents a very, very brief overview of that algorithm
  188. and modifications made to that algorithm to overcome its weaknesses and
  189. to allow support for a 3 file comparison.
  190. .H 2 "Term Definition"
  191. This section contains definitions of several terms
  192. used in the description of the algorithm.
  193.  
  194. The 'current file' is one of the files being compared.
  195. At any point in the algorithm, the 'current
  196. file' is the one which is being compared to the 'corresponding file'.
  197. The 'other file' is the file which is neither the current file
  198. nor the corresponding file.
  199. .H 2 "Record Array Description"
  200. For each file which is being compared, a record array exists. There is one
  201. entry in the array for every record in the file. There is also a dummy entry
  202. at the beginning of the array and a dummy entry at the end of the array. These
  203. dummy entries allow easy detection of beginning of file and end of file.
  204.  
  205. Each entry in the array contains an 'rfa'. An 'rfa' is a
  206. record's file address. An rfa can be used to position the file to the particular
  207. record. On VOS, the rfa is merely the record's CRA (current record address).
  208. On UNIX, the rfa is byte displacement into the file.
  209.  
  210. Each entry in the array also contains two 'value' fields. Each value field
  211. describes the relationship between the current file and the other two files.
  212. The content of the value field will become obvious as we progress through
  213. the description of the algorithm. For now, suffice it to say that the field
  214. contains either a negative displacement into the symbol table or a positive
  215. displacement into the record array of the corresponding file.
  216. .H 2 "Symbol Table Description"
  217. The symbol table consists of four arrays each indexed by the same value.
  218. The index into the symbol table is a unique
  219. hash code computed from the text of the record from any of the files. Identical
  220. records always hash to the same location. Different records always hash to
  221. different locations.
  222.  
  223. The first symbol table array is the cache pointer array.
  224. The value in this array is 0 if the symbol
  225. table entry is not used. The value is a pointer to the cache entry if
  226. the symbol table entry is used and the record is still in cache. The value
  227. is -1 if the symbol table entry is used but the record is not in cache.
  228.  
  229. One symbol table array exists for each file being compared. The value in
  230. this array is 0 if the hashed record does not occur in the current file at all.
  231. The value is a positive record number if the hash record occurs in the
  232. current file precisely once. The value is a negative record number if the
  233. hash code occurs in the current file more than once.
  234. .H 2 Cache
  235. The cache maintains a copy of the text of the 300 most recently read records.
  236. Combine ensures that two records that hash to the same value are indeed
  237. the same record by comparing actual record contents. The cache allows the
  238. comparison to be done efficiently. See the description of pass1 for detailed
  239. information.
  240. .H 2 Pass1
  241. Pass1 reads all of the records from all of the files and initializes the
  242. symbol table and record arrays. On completion of this pass,
  243. the symbol table is initialized as described above and the record array
  244. for each file contains a negative hash code for each record in the file.
  245.  
  246. Pass1 reads a record from a file into a cache entry.
  247. Pass1 then computes the hash code for the record.
  248. If the hash code has never been used before, pass1 links the cache entry from
  249. the symbol table, marks the symbol table of the current file to indicate
  250. that this line exists precisely once in the file, and marks the record array
  251. of the current file to contain the negative hash code.
  252.  
  253. If the hash code has been used before, the value of the current record is
  254. compared with the value of the other record which hashed to the same value.
  255. The other record is either already in cache or is read into cache at this
  256. time.
  257.  
  258. If the current record and the other record are the same, pass1 marks the
  259. symbol table of the current file to indicate that this line exists in the
  260. file and marks the record array of the current file to contain the negative
  261. hash code. This condition can occur under two circumstances. First, a
  262. record from one file and the same record from the corresponding file will
  263. hash to the same location. Second, a record from one file and the same
  264. record at a different location in the same file will hash to the same location.
  265. The symbol table entry is marked to indicate whether a record occurs precisely
  266. once in a particular file or whether is occurs multiple times in a particular
  267. file.
  268.  
  269. If the current record and the other record are different, pass1 computes a
  270. different hash code for the current record and the above
  271. algorithm is repeated.
  272.  
  273. Pass1 alternately reads one record from each file. Thus, if a record is read
  274. into cache on the first file, the record will probably still be in cache
  275. when it is read on the second file. Cache is only used as described here in
  276. pass1. Nothing in the cache is passed between passes.
  277. .H 2 Pass2
  278. Pass2 determines anchor points in the files. Pass2 identifies lines
  279. which occur precisely once in at least two of the files and no more than
  280. once in the third file. On completion of this pass, the record array
  281. for each file
  282. contains either a negative hash code for those records which don't meet
  283. the above criteria or contains a positive index into the record array
  284. of the corresponding file for those records which do meet the criteria.
  285. The symbol table is no longer used following this pass.
  286. .H 2 Pass3
  287. Pass3 expands the anchor points to non-unique records. A non-unique record
  288. is a record which occurs more than once in at least one file. On completion
  289. of this pass, record array for each file will contain more positive indexes
  290. into the record array of another file and less negative hash codes.
  291. In general, following this pass, records which have negative hash codes
  292. are records which exist in the current file and have absolutely no corresponding
  293. records in the corresponding file. (I'll be more specific on this when I
  294. discuss pass4.)
  295.  
  296. Each pair of two files is scanned first in the forward direction and then
  297. in the backward direction. If, in the pair of files, there are lines which
  298. are adjacent to an anchor point and which are identical to each other, these
  299. lines are considered to be anchor points themselves. Lines are compared by
  300. comparing their negative hash codes.
  301. .H 2 Pass4
  302. Pass4 expands the anchor points into non-unique record clusters.
  303. Pass4 tries to fix up problems which arise due to groups of non-unique
  304. records which are surrounded by insertions. When pass3 completed these
  305. records were treated as a part of the insertion. If, indeed, a large
  306. portion of the insertion actually matches a large portion of an insertion
  307. in another file, but if the match went undetected because the records
  308. were non-unique, then pass4 finds these non-unique lines and matches them.
  309.  
  310. Pass4 finds a pair of anchor records which have inserted lines between
  311. them (See diagram below). All inserted lines are compared to one another
  312. trying to find a group of non-unique lines which match. Such lines are
  313. considered equal and are flagged as anchor points.
  314.  
  315.           match1                       match1
  316.           insert
  317.           non-unique1                  non-unique1
  318.           insert
  319.           match2                       match2
  320.  
  321. The current implementation of the algorithm runs in M x N time where M is
  322. the number of inserted lines at the current position in the first file and
  323. N is the number of inserted lines at the current position in the second file.
  324. .H 2 Pass5
  325. Pass5 outputs the result of the comparison. The record arrays for the
  326. three files are traversed. An index is maintained into each of the record
  327. arrays. As each index is incremented the corresponding record is output.
  328. Pass5 merely determines which file the next record is to come from.
  329.  
  330. The hardest problem for pass5 to resolve is one of record movement. That is,
  331. if a group of records from one file is moved to a different position in the
  332. second file. In this situation, the 'shortest' group of records is considered
  333. to have moved. This group of records is output first by pass5.
  334.  
  335. Pass5 uses the record cache to maintain a list of the last several records
  336. output. This cache is used to enable the 'prefix' lines capability of
  337. the comparison listing.
  338.